package com.easylinkin.linkappapi.project.controller;


import com.easylinkin.linkappapi.project.entity.Project;
import com.easylinkin.linkappapi.project.entity.dto.ProjectFromEnterprise;
import com.easylinkin.linkappapi.project.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author TongJie
 * @since 2020-04-16
 */
@RestController
@RequestMapping("/project")
public class ProjectController {

    @Autowired
    private ProjectService service;

    @GetMapping("getIdByName")
    public RestMessage getIdByName(@RequestParam("name") String name) {

        return RestBuilders.successBuilder().data(service.getIdByName(name)).build();
    }

    /**
     * 新增项目
     */
    @PostMapping("addProject")
    public RestMessage addProject(@RequestBody Project project) {
        service.addProject(project);
        return RestBuilders.successBuilder().build();
    }

    @GetMapping("getInfo")
    public RestMessage getInfo() {
        return RestBuilders.successBuilder().data(service.getInfo(null)).build();
    }

    @PostMapping("updateInfo")
    public RestMessage updateInfo(@RequestBody ProjectFromEnterprise projectFromEnterprise) {
        return RestBuilders.successBuilder().data(service.updateInfo(projectFromEnterprise)).build();
    }

}
